package com.ccp.dev.core.util;

import java.io.Serializable;

public class ParamEncoder implements Serializable {
    private static final long serialVersionUID = 899149338534L;
    private String parameterIdentifier;

    public ParamEncoder(String idAttribute) {
        String stringIdentifier = "x-" + idAttribute;
        char[] charArray = stringIdentifier.toCharArray();
        int checkSum = 17;

        for (int j = 0; j < charArray.length; ++j) {
            checkSum = 3 * checkSum + charArray[j];
        }

        checkSum &= 8388607;
        this.parameterIdentifier = "d-" + checkSum + "-";
    }

    public String encodeParameterName(String paramName) {
        return this.parameterIdentifier + paramName;
    }

    public boolean isParameterEncoded(String paramName) {
        return paramName != null && paramName.startsWith(this.parameterIdentifier);
    }
}